import Vue from "vue";

//按钮节流
const preventReClick = Vue.directive("preventReClick", {
  inserted: function (el, binding) {
    el.addEventListener("click", () => {
      if (!el.disabled) {
        el.disabled = true;
        setTimeout(() => {
          el.disabled = false;
        }, binding.value || 3000);
      }
    });
  },
});

//阻止默认行为，禁用右键菜单
const disableRightClick  = Vue.directive('disable-right-click', {
  bind: function (el, binding) {
    // 监听右键点击事件
    el.addEventListener('contextmenu', function (event) {
      // 根据特定条件判断是否阻止默认行为
      if (binding.value) {
        event.preventDefault(); // 阻止默认行为，禁用右键菜单
      }
    });
  }
});

export { preventReClick,disableRightClick };
